/* -*- mode: c++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- */

#ifndef _TIMESEQ_H_
#define _TIMESEQ_H_

#include <stdio.h>
#include <time.h>

#include <string>

#include <utility.h>

class TimeSeq {
public:
    time_t              last_time;

    int                 seq;

    TimeSeq() : last_time(0)
              , seq(0)
    {
    }

    void get(std::string& s, const char *fmt = NULL)
    {
        time_t now = time(NULL);

        if (now != last_time) {
            seq = 0;
            last_time = now;
        }

        if (fmt == NULL)
            get_curr_time(s);
        else
            get_curr_time_spec(s, fmt);

        if (seq > 0) {
            char buf[32];
            sprintf(buf, "-%d", ++seq);
            s += buf;
        }
        else
            ++seq;
    }
};

#endif /* _TIMESEQ_H_ */
